﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Streambolics
{
    public class DirectoryEnumerator
    {
        private DirectoryInfo _BaseDir;
        private string _Pattern;

        public DirectoryEnumerator (DirectoryInfo ABaseDir, string APattern)
        {
            _BaseDir = ABaseDir;
            _Pattern = APattern;
        }

        IEnumerable<FileInfo> Files
        {
            get
            {
                foreach (DirectoryInfo d in _BaseDir.GetDirectories())
                {
                    DirectoryEnumerator de = new DirectoryEnumerator (d, _Pattern);
                    foreach (FileInfo f in de.Files)
                    {
                        yield return f;
                    }
                }

                foreach (FileInfo f in _BaseDir.GetFiles (_Pattern))
                {
                    yield return f;
                }
            }
        }
    }
}
